#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

int distanceTraveled(int mainTank, int additionalTank)
{
    if (mainTank < 5)
        return mainTank * 10;
    int rank = 0;
    while (mainTank >= 5)
    {
        rank += 5;
        mainTank -= 5;
        if (additionalTank >= 1)
        {
            mainTank += 1;
            additionalTank -= 1;
        }
    }
    rank += mainTank;
    return rank * 10;
}